import numpy as np

def random_det():
    A = np.random.randint(0, 9, 9)
    B = A.reshape(3, 3)
    return [A,B]

def solve_det(A):
    C = round(np.linalg.det(A),)
    return C

if __name__ == '__main__':
    quits,answers,answerss = [],[],[]
    for ix in range(1,208):
        x = random_det()
        x0 = x[0]
        x1 = x[1]
        y = solve_det(x[1])
        a,b,c,d,e,f,g,h,i,j = x0[0],x0[1],x0[2],x0[3],x0[4],x0[5],x0[6],x0[7],x0[8],y
        if ix < 10:
            ix_str = '00'+str(ix)
        elif ix < 100 and ix >=10:
            ix_str = '0'+str(ix)
        else:
            ix_str= str(ix)
        line0 = '$'+ix_str+ '. \\begin{vmatrix} '
        line00 = '$\\\\'+ix_str+ '. \\begin{vmatrix} '
        line1 = '{}&{}&{}\\\\{}&{}&{}\\\\{}&{}&{} '.format(a,b,c,d,e,f,g,h,i)
        line2 = '\end{vmatrix} '
        line3 = '= {} \qquad \\\\ $'.format(y)
        line4 = '= {} \qquad  $'.format(y)
        line31 = '=    \qquad \\\\ $'
        line41 = '=    \qquad  $'
        answers_str = ix_str+'.det='+str(y)
        if ix == 0:
            j1 = line00 + line1 + line2 + line31
        if (ix)%3== 0:
            j1 = line0 + line1 + line2 + line31
            quits.append(j1)
        else:
            if ix == 1:
                j1 = line00 + line1 + line2 + line41
                quits.append(j1)
            else:
                j1 = line0 + line1 + line2 + line41
                quits.append(j1)
        answers.append(answers_str)
    print('原题\n')
    for item in quits:
        print(item)
    for xx in range(0,len(answers)):
        if (xx+1)%5 == 0:
            answerss.append(answers[xx]+'\\\\')
        else:
            answerss.append(answers[xx])
    print(answerss)
